import logging
import unittest
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from Page import Page
from Page2 import Page2
from Page3 import Page3
from ddt import ddt,file_data
from Tools import Tools

@ddt
class Case(unittest.TestCase):
    def setUp(self):
        print('start case')
        Tools().Report()
        self.driver = webdriver.Edge()
        self.driver.maximize_window()

    def tearDown(self):
        print('end case')
        time.sleep(5)
        # 关闭浏览器驱动
        self.driver.quit()

    # 添加版本号
    def test_01(self):
        po = Page(self.driver)
        po.open_url('http://localhost:8081/ykVersionslist')
        time.sleep(3)
        # 断言1-
        dy1 = self.driver.find_element(By.XPATH,'/html/body/div[1]/div/section/section/main/div[1]/div[1]/div[1]/div[2]/table/thead/tr/th[3]/div').text

        print('断言1：',dy1)
        self.assertEquals('版本名称',dy1)
        time.sleep(2)
        # 1.点击新增按钮
        po.click_addbtn()
        time.sleep(1)
        # 2.输入版本名称
        po.sr_versionname()
        time.sleep(1)
        # 3.输入发布日期
        po.sr_releasedate()
        time.sleep(1)
        # 4.点击版本状态框
        po.click_statusK()
        time.sleep(1)
        # 5.点击状态
        po.click_status()
        time.sleep(1)
        # 6.点击提交
        po.click_com()
        time.sleep(5)
        # 处理弹窗
        alert = self.driver.switch_to.alert
        alert.accept()
        time.sleep(5)

    # 查询版本号名称
    @file_data('data.json')
    def test_02(self,name):
        po = Page2(self.driver)
        po.open_url('http://localhost:8081/ykVersionslist')
        time.sleep(3)
        # 断言
        dy1 = self.driver.find_element(By.XPATH,'/html/body/div[1]/div/section/section/main/div[1]/div[1]/div[1]/div[2]/table/thead/tr/th[3]/div').text

        print('断言1：',dy1)
        self.assertEquals('版本名称',dy1)
        time.sleep(2)
        po.sr_banbenname(name)
        time.sleep(1)
        # 2.点击搜索按钮
        po.click_search()
        time.sleep(5)
        po.sr_banbenname(name)
        time.sleep(1)
        # 2.点击搜索按钮
        po.click_search()
        time.sleep(5)

    # 删除版本号
    def test_03(self):
        po = Page3(self.driver)
        po.open_url('http://localhost:8081/ykVersionslist')
        time.sleep(3)
        # 断言1-
        dy1 = self.driver.find_element(By.XPATH,
                                       '/html/body/div[1]/div/section/section/main/div[1]/div[1]/div[1]/div[2]/table/thead/tr/th[3]/div').text

        print('断言：', dy1)
        self.assertEquals('版本名称', dy1)
        time.sleep(2)
        po.click_scbtn()
        time.sleep(5)

if __name__ == '__main__':
    unittest.main()

